﻿/**********************************************
系统:Ebada物流企业ERP
模块:示例
作者:Rabbit
创建时间:2011-2-28
最后一次修改:2011-2-28
***********************************************/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Ebada.Platform.Model;
using DevExpress.XtraGrid.Columns;
using System.Reflection;
using Ebada.Client;
using DevExpress.XtraGrid.Views.Base;
using Ebada.Client.Platform;
using System.Collections;

namespace Ebada.Modules.Vehicle
{

    public partial class UCAccident : DevExpress.XtraEditors.XtraUserControl
    {
        private GridViewOperation<VehicleAccident> gridViewOperation;
        public event SendDataEventHandler<VehicleAccident> FocusedRowChanged;
        private VehicleAccident row;
        frmAccidentEdit f = new frmAccidentEdit();


        public UCAccident()
        {
            InitializeComponent();
            initImageList();
            gridViewOperation = new GridViewOperation<VehicleAccident>(gridControl1, gridView1, barManager1, f);
            gridViewOperation.CreatingObjectEvent += gridViewOperation_CreatingObjectEvent;
            gridViewOperation.BeforeAdd += new ObjectOperationEventHandler<VehicleAccident>(gridViewOperation_BeforeAdd);
            gridViewOperation.AfterAdd += new ObjectEventHandler<VehicleAccident>(gridViewOperation_AfterAdd);
            gridViewOperation.BeforeEdit += new ObjectOperationEventHandler<VehicleAccident>(gridViewOperation_BeforeEdit);
            gridView1.FocusedRowChanged += new DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventHandler(gridView1_FocusedRowChanged);
            initColumns();
            LoadData();
        }

        void gridViewOperation_BeforeEdit(object render, ObjectOperationEventArgs<VehicleAccident> e)
        {

        }


        /// <summary>
        /// 设置隐藏列
        /// </summary>
        void initColumns()
        {
            gridView1.Columns[0].Visible = false;
            gridView1.Columns[17].Visible = false;
            this.gridView1.Columns[26].ColumnEdit = this.repositoryItemImageEdit1;
            this.repositoryItemImageEdit1.AutoHeight = false;
            this.repositoryItemImageEdit1.Buttons.AddRange(new DevExpress.XtraEditors.Controls.EditorButton[] {
            new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo)});
            this.repositoryItemImageEdit1.Name = "repositoryItemImageEdit1";
            this.repositoryItemImageEdit1.SizeMode = DevExpress.XtraEditors.Controls.PictureSizeMode.Zoom;
            gridView1.Columns[26].Visible = false;
        }
        public void hidebutton()
        {
            this.btAdd.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
            this.btClose.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
            this.btEdit.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
            this.btExport.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
            this.btDelete.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;

        }
        void gridViewOperation_BeforeAdd(object render, ObjectOperationEventArgs<VehicleAccident> e)
        {

        }
        void gridViewOperation_AfterAdd(object render)
        {

        }
        public void LoadData()
        {
            gridViewOperation.RefreshData(" where 1=1 order by OperDate desc,VehicleNumber");
        }
        private void initImageList()
        {
            ImageList imagelist = new ImageList();
            imagelist.ImageStream = (Ebada.Client.Resource.UCGridToolbar.UCGridToolbarImageList);
            barManager1.Images = imagelist;
        }
        void gridView1_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            if (FocusedRowChanged != null)
            {
                FocusedRowChanged(gridView1, gridView1.GetFocusedRow() as VehicleAccident);

            }
            row = gridView1.GetFocusedRow() as VehicleAccident;
        }
        /// <summary>
        /// 封装了数据操作的对象
        /// </summary>
        [Browsable(false)]
        public GridViewOperation<VehicleAccident> GridViewOperation
        {
            get { return gridViewOperation; }
            set { gridViewOperation = value; }
        }
        /// <summary>
        /// 新建对象设置Key值
        /// </summary>
        /// <param name="newobj"></param>
        void gridViewOperation_CreatingObjectEvent(VehicleAccident newobj)
        {

        }

    }
}
